package com.mall.users.controller;

import com.mall.commons.utils.CommonResult;
import com.mall.model.domain.UmsMenu;
import com.mall.model.domain.UmsResource;
import com.mall.model.vo.CommonPage;
import com.mall.users.service.UmsResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/resource")
public class UmsResourceController {

    @Autowired
    private UmsResourceService umsResourceService;

    /**
     * 查询所有后台资源
     * @return
     */
    @GetMapping("/listAll")
    public CommonResult listAll() {
        List<UmsResource> list = umsResourceService.listAll();
        return CommonResult.success(list);
    }

    /**
     * 分页模糊查询后台资源
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam Map map) {
        CommonPage page = umsResourceService.list(map);
        return CommonResult.success(page);
    }

    /**
     * 根据ID获取资源详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult getById(@PathVariable Long id) {
        UmsResource umsResource = umsResourceService.getById(id);
        return CommonResult.success(umsResource);
    }

    /**
     * 根据ID删除后台资源
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Long id) {
        umsResourceService.delete(id);
        return CommonResult.success(1);
    }


    /**
     * 添加后台资源
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody UmsResource umsResource) {
        umsResourceService.create(umsResource);
        return CommonResult.success(1);
    }

    /**
     * 修改后台资源
     * @param id
     * @param umsResource
     * @return
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable Long id, @RequestBody UmsResource umsResource) {
        umsResourceService.update(umsResource);
        return CommonResult.success(1);
    }

}
